public class WorldIndex {

    public int getIndex(String[] worlds,String world1,String world2){
        int index1=-1;
        int index2=-1;
        int res=worlds.length;
        for (int i = 0; i <worlds.length ; i++) {
            if (world1.equals(worlds[i])) {
                index1 = i;
            }
            if (world2.equals(worlds[i])) {
                index2 = i;
            }
            if(index1>0&&index2>0){
                res=Math.min(res,Math.abs(index1-index2));
            }
        }
        return res;
    }
}
